﻿/********************************************************************************
** @ Date:2023/03/07
** @ Author: Gaojia
** @ Description:  地图基类
** @ Version:1.0.0
** @ Fun:
********************************************************************************/
#ifndef CMapWidgetBase_H
#define CMapWidgetBase_H
#include <qwidget.h>
#include <QMutex>
#define DiamSmall 8
#define DiamLarge 10
#define DiamGuanghuan      13
#define DiamGuanghuanSmall   15
#define DiamGuanghuanLarge   25
#define SketcgLength 0.15
#define PI 3.1415926535898
#define PAI (PI/180)

struct PointData
{
	QPointF m_dOriPoint;         //原始坐标，单位是mm
	QPointF m_dConvertPoint;     //转换过后的坐标点，将原始坐标根据具体的地图的大小转换成像素以后的坐标
	QPointF m_dZoomPoint;        //缩放过后点坐标，原始像素坐标的基础上，通过滚轮缩放比例后计算生成的坐标
	double m_dRadius;            //半径
	PointData()
	{
		m_dOriPoint.setX(0);
		m_dOriPoint.setY(0);
		m_dConvertPoint.setX(0);
		m_dConvertPoint.setY(0);
		m_dZoomPoint.setX(0);
		m_dZoomPoint.setY(0);
		m_dRadius = 0;
	}
};

class CMapWidgetBase :
	public QWidget
{
public:
	CMapWidgetBase(QWidget *parent = nullptr);
	~CMapWidgetBase();
	void setPoints(const QVector<QPointF> &points, QVector<int> vecXData);//往地图里写点
	void setActPoints(int nXVal,bool bCharge=false);//设置当前执行到的点

protected:
	void resizeEvent(QResizeEvent *event)override;
	void paintEvent(QPaintEvent *event) override;
	void mousePressEvent(QMouseEvent *event) override;  //重写鼠标按下事件
	void mouseMoveEvent(QMouseEvent *event) override;   //重写鼠标移动事件
	void mouseReleaseEvent(QMouseEvent *event) override;//重写鼠标松开事件
	void wheelEvent(QWheelEvent *event) override;       //重写鼠标滚轮事件
	void clearPoints();                                 //清空地图中的点
	void GetXYMaxMin();                                 //获取xy方向上的最大值与最小值
	void GetDrawActPoint();

protected:
	QMutex m_MutexOriData;//操作原始数据锁
	QVector<QPointF> m_vecOripoints;    //原始坐标点单位mm
	QVector<int>     m_vecXdata;        //原始执行走过的距离单位mm
	QVector<QPointF> m_vecPoints;       //转换过后坐标点   
	QVector<QPointF> m_vecActPoints;    //执行过的坐标点单位mm
	
	QPoint m_lastPos;
	bool m_isDragging;	//是否允许拖拽
	qreal m_scale;      //比例
	QPoint m_translation;
	bool   m_bChargeFlicker;
	bool   m_bFlicker;	//是否闪烁
	QSize  m_cWidgetSize;
	int   m_nXMax;      //X方向最大值
	int   m_nXMin;      //X方向最小值
	int   m_nYMax;      //Y方向最大值
	int   m_nYMin;      //Y方向最小值

	int m_dRotateAngle;   //实时旋转角度
	int m_dRotateAngleOld;//缓存角度(用于比较角度变化)
public:
	int m_nXval;		  //当前机器人运行到的点
};

#endif